package MySql;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class MysqlSelect {
    public static boolean MySQL_FindQQ(String QQ)  {
        boolean pass=false;
        Connection conn = null;
        Statement stmt = null;
        try {
            //注册jdbc驱动
            conn = MysqlOperate.getConn();
            stmt = conn.createStatement();
            String sql="SELECT 1 FROM person WHERE qq="+QQ+" LIMIT 1;";
            System.out.println("数据库操作：" + sql);
            ResultSet rs = stmt.executeQuery(sql);//创建数据对象
           if(rs.next()&&rs!=null) {

               if (rs.getString(1) != null && rs.getString(1).equals("1")) {
                   pass = true;
               } else {
                   pass = false;
               }
           }
        } catch (Exception e) {
            e.printStackTrace();
            return pass;
        }finally {
            try {
                MysqlOperate.closeall(null, null, conn,stmt);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
        return pass;
    }
    public static boolean MySQL_Checkpassword(String QQ,String password)  {
        boolean pass=false;
        Connection conn = null;
        Statement stmt = null;
        try {
            //注册jdbc驱动
            conn = MysqlOperate.getConn();
            stmt = conn.createStatement();
            String sql="select password from person where qq="+QQ;
            System.out.println("数据库操作：" + sql);
            ResultSet rs = stmt.executeQuery(sql);//创建数据对象
            if(rs.next()&&rs!=null) {
                if (rs.getString(1) != null && rs.getString(1).equals(password)) {
                    pass = true;
                } else {
                    pass = false;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return pass;
        }finally {
            try {
                MysqlOperate.closeall(null, null, conn,stmt);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
        return pass;
    }
}
